function su_check_managed_folder_emptiness(folderid)
{
var hs = su_ds.getHistoryService();
var query;
var result;
var bms;
var db;
var sql;
// if the managed folder is now empty, remove it.
query = hs.getNewQuery();
query.setFolders([folderid], 1);
result = hs.executeQuery(query, hs.getNewQueryOptions());
result.root.containerOpen = true;
if (result.root.childCount == 0)
{
bms = su_ds.getBookmarksService();
bms.removeItem(folderid);
db = su_ds.getDatabase();
sql = "DELETE FROM supertopic WHERE bm_folderid=" + db.v(folderid);
db.query(sql);
}
}
function su_get_rating(url, stumblevideo, opt_url_detail)
{
if (opt_url_detail)
return opt_url_detail.rating;
if (su_host.places && ! stumblevideo)
{
var db = su_ds.getDatabase();
var result;
var row;
var sql;
sql = "SELECT rating FROM url_map NATURAL JOIN url WHERE url=" + db.q(url);
result = db.query(sql);
if (row = result.shift())
{
return (row.rating == -1) ? null : row.rating;
}
else if ((typeof su_ratings[url]) != "undefined")
{
// We're generating too many hits.
if (! su_ds.lookup("url:rating_getmeta_flag", url))
{
su_ds.define("url:rating_getmeta_flag", url, 1);
su_rate_getmeta(url, false);
}
return su_ratings[url];
}
else
{
return null;
}
}
else
{
if ((typeof su_ratings[url]) == "undefined")
return null;
else
return su_ratings[url];
}
}
function su_get_tag_list(url)
{
var retval = null;
if (((typeof (su_tag_lists_by_url[url])) != "undefined") &&
(su_tag_lists_by_url[url] != ""))
{
retval = su_tag_lists_by_url[url];
}
else if (su_host.places)
{
var db = su_ds.getDatabase();
var result;
var row;
var sql;
var tags = new Array();
sql = "SELECT tag FROM url_map NATURAL JOIN url_tag NATURAL JOIN tag_map WHERE url=" + db.q(url) + " AND url_tag.tagid>1000 AND url_tag.tagid!=" + db.v(su_video_tagid);
result = db.query(sql);
if (result.length)
{
while (row = result.shift())
tags.push(row.tag);
retval = tags.join(", ");
su_tag_lists_by_url[url] = retval;
}
}
return retval;
}
// returns true/false is domain is blocked or not
function su_is_domain_blocked(domain)
{
if (! su_host.places)
return false;
var out = false;
try {
var db = su_ds.getDatabase();
var sql;
var result;
sql = "SELECT active FROM blocked_domain WHERE domain=" + db.q(domain) + " AND active=1";
result = db.query(sql);
out = (result.length) ? true : false;
} catch (e) {} // be safe since this is within the stumbling path
// If a folder with this name exists in their su bookmarks folder,
// use it.
var folderid = bms.getChildFolder(
su_ds.getValue("$bm_folderid"),
folder_name);
if (folderid != 0)
return folderid;
// Otherwise, try to use the most recent one that we created, even
// if they moved or renamed it.
var db = su_ds.getDatabase();
var result;
var index;
var row;
var sql;
sql = "SELECT bm_folderid FROM supertopic WHERE label=" + db.q(folder_name);
result = db.query(sql);
index = -1;
if (row = result.shift())
{
folderid = row.bm_folderid;
index = bms.getItemIndex(folderid);
}
if (index != -1)
return folderid;
else if (! create)
return null;
// Do a sanity check to make sure we're allowed to create it.
if ((folder_name == "Adult") && (! su_ds.getValue("$sync_bm_adult")))
return null;
// Create a new one in alphabetical order with our other
// automatically generated supertopic folders; make the
// 'Other Tagged' folder always last.
index = -1;
if (catid != -1)
{
sql = "SELECT label,bm_folderid FROM supertopic WHERE label>" + db.q(folder_name) + " AND label!=" + db.q(su_tagged_folder_name) + " ORDER BY label LIMIT 1";
result = db.query(sql);
if (row = result.shift())
{
try {
index = bms.getItemIndex(row.bm_folderid);
} catch (e) {}
}
}
folderid = null;
try {
folderid = bms.createFolder(
su_ds.getValue("$bm_folderid"),
folder_name,
index);
var index2 = bms.getItemIndex(folderid);
db.a("INSERT OR REPLACE INTO supertopic (label,bm_folderid) VALUES (");
db.as(folder_name);
db.alv(folderid);
db.query();
} catch (e) { su_log_error("CREATE FOLDER", e); }
// Update the video query to include this new folder.
if (folderid)
su_refresh_video_folder_bm();
return folderid;
}
function su_refresh_video_folder_bm()
{
var db = su_ds.getDatabase();
var sql;
var result;
var row;
sql = "SELECT bm_folderid FROM supertopic ORDER BY label";
var seq = su_ds.lookup("domain:tomore_favicon_list", spec.domain);
if (seq)
{
text = document.createTextNode("Have fun with " + su_ds.getThruDomainChannel(spec.domain).name + " pages! You can StumbleThru this and other websites ");
var alerttext = "To tag a page, type some tags into the text box before clicking the tag button.\nTags are descriptive keywords you can use to organize and share useful websites.\nTags may contain spaces, letters, and numbers and must be separated by commas.\nFor example, you might tag page of travel photos as \"photos, traveling, costa rica\".\n\nYou can lookup sites you've tagged using the 'Find pages you liked' button on your Favorites page.";
tagerror = 'You cannot apply more than 5 tags to a page.';
break;
}
var thetag = tags[i];
if (thetag.indexOf('http://') != -1)
{
tagerror = 'If you want to search for a site, enter some search terms then click \'enter\'.\nTo tag a page, type in some keywords before clicking this icon.';
break;
}
if (thetag.length > 32)
{
tagerror = 'Each tag cannot be longer than 32 characters.\nYour tag \'' + thetag + '\' is ' + thetag.length + ' characters long.';
break;
}
var tagpieces = thetag.split(/[^A-Za-z0-9]/);
// alert(tagpieces.length);
var tagpiececount = 0;
for (var j = 0; j < tagpieces.length; j++)
{
if (tagpieces[j] == "")
continue;
//alert(tagpieces[j]);
tagpiececount++;
if (tagpiececount > 3)
{
tagerror = 'Each tag cannot have more than 3 words. For example,\n \'costa rica trip\' is a valid tag, but \'costa rica trip photos\' is not.\nYour tag \'' + thetag + '\' has ' + tagpiececount + ' words.';
break;
}
}
if (tagpiececount > 3)
break;
}
return tagerror;
}
function su_tagit(url, tag, untag, opt_title, opt_raw_url)
{
// when you tag, we know it's not a tag on i-likeit